package com.project.common.core.domain;

import com.project.common.utils.DateUtils;
import com.project.common.utils.SecurityUtils;

/**
 * @ClassName: BaseServer
 * @Author: kang
 * @Date: 2021/4/8　14:09
 * @Description：
 */
public abstract class BaseServer {

    /**
     * 新增信息
     *
     * @param entity 信息
     * @return 结果
     */
    public void insert(BaseEntity entity) {
        if (entity == null) return;
        entity.setCreateBy(getUsername());
        entity.setCreateTime(DateUtils.getNowDate());
    }

    /**
     * 修改信息
     *
     * @param entity 信息
     * @return 结果
     */
    public void update(BaseEntity entity) {
        if (entity == null) return;
        entity.setUpdateBy(getUsername());
        entity.setUpdateTime(DateUtils.getNowDate());
    }

    private String getUsername() {
        String username = "admin";
        try {
            username = SecurityUtils.getUsername();
        } catch (Exception e) {
        } finally {
            return username;
        }
    }
}
